import pandas as pd
from tkinter import Tk
from tkinter.filedialog import askopenfilename
import FindData
import WellTrajectoryData
from Compute import EstimateEigenvalues, TrueThickness, AngularDifference, PointAPrediction, TrueInclination


class ExcelReader:
    def __init__(self):
        self.file_path = self.select_file()
        if not self.file_path:
            raise ValueError("请选择一个有效的文件")
        self.data = self.read_data()

    def select_file(self):
        # 选择Excel文件
        file_path = askopenfilename(filetypes=[("Excel files", "*.xlsx *.xls")])
        return file_path

    def read_data(self):
        # 读取Excel文件中的数据
        if not self.file_path:
            raise ValueError("请选择一个有效的文件")

        # 读取指定范围的数据
        data = pd.read_excel(self.file_path, usecols="B:M", skiprows=10, nrows=1044)
        return data


# 示例用法
if __name__ == "__main__":
    reader = ExcelReader()
    print(reader.data)
    excel_finder = FindData.ExcelFinder(reader.data)
    data1 = excel_finder.find_data(40)
    ee1 = EstimateEigenvalues(data1)
    excel_data1 = ee1.estimate_eigenvalues(40)
    data2 = excel_finder.find_data(50)
    ee2 = EstimateEigenvalues(data2)
    excel_data2 = ee2.estimate_eigenvalues(50)
    tt = TrueThickness()
    true_thickness = tt.calculate_true_thickness(excel_data1, excel_data2, 15, True)
    print(true_thickness)
    true_thickness1 = tt.calculate_true_thickness(excel_data1, excel_data2, 15, False)
    print(true_thickness1)
    ad = AngularDifference()
    angular_difference1 = ad.calculate_angular_difference(99, 90, 5, 1, True)
    angular_difference2 = ad.calculate_angular_difference(99, 90, 5, 1, False)
    print(angular_difference1)
    print(angular_difference2)
    pa = PointAPrediction()
    point_a_prediction1 = pa.predict_point_a(224, 4, 4027, 310, True)
    point_a_prediction2 = pa.predict_point_a(224, 4, 4027, 310, False)
    print(point_a_prediction1)
    print(point_a_prediction2)
    ti = TrueInclination()
    true_inclination1 = ti.calculate_true_inclination(294, 717, 3, True)
    true_inclination2 = ti.calculate_true_inclination(294, 717, 3, False)
    print(true_inclination1)
    print(true_inclination2)
